include ../SETTINGS

phony:
	echo You must use explicitly one of the available targets

exec_headers: make_header create_ini
	for F in dbcommonclient dbcommonselection dbclient dbtemplates dbselection dbcreatetable dbeditclient dbeditselection dboptions dbserverstatus dbserverstop ; do cat ./header $$F > $$F.cgi ; chmod a+x $$F.cgi ; done
	cat ./header dbserver.bare > dbserver ; chmod a+x dbserver

make_header:
	$(RM) -f header
	echo '#!/bin/sh' > header
	echo "exec $(CIAOBIN)/ciaoengine"' "$$@" -C -b $$0' >> header

exec: 	create_passwd create_ini create_passwd create_address	
	$(CIAOC) -x -s -o db_generic_client.cgi db_generic_client
	$(CIAOC) -x -s -o db_maintenance.cgi db_maintenance
	$(CIAOC) -x -s -o webdb_client.cgi webdb_client
	$(CIAOC) -x -s -o webdb_front.cgi webdb_front
	$(CIAOC) -x -s -o dbserverstop.cgi dbserverstop	
	$(CIAOC) -x -s -a 'actmods/filebased_publish' dbserver
	$(CHMOD) a-r password.pl

create_ini:
	echo "% This file is created by Makefile" > dbserver_ini.pl
	echo "db_dir('$(DBHOME)')."      	   >> dbserver_ini.pl
	echo "db_url('$(DBURL)')."          	   >> dbserver_ini.pl
	echo "db_description('$(DBDESC)')." 	   >> dbserver_ini.pl
	echo "db_data('$(DBDATA)')."               >> dbserver_ini.pl
	echo "db_types('$(DBTYPES)')."             >> dbserver_ini.pl
	echo "db_templates('$(DBTEMPLATES)')."     >> dbserver_ini.pl

create_passwd:
	/bin/rm -f password.pl
	echo "password($$$$)." > password.pl

create_address:
	echo "'$(DBADD)'." > $(DBHOME)/.addr
	echo "'$(DBADD)'." > $(DBHOME)/admin/.addr

install: maintenance
	$(MV) webdb_client.cgi webdb_front.cgi $(DBHOME)
	$(MV) dbserverstop.cgi db_generic_client.cgi db_maintenance.cgi $(DBHOME)/admin
	$(CP) dbserver dbserver_ini.pl maintenance.html $(DBHOME)/admin

maintenance:
	$(RM) -f ./.addr
	$(RM) -f ./.lock
	echo "'$(DBADD)'." > ./.addr
	./dbserver; $(CP) maintenance.html $(DBHOME)/admin
	$(RM) -f ./.addr

clean:
	$(RM) -f *.po *.itf *.dep tmp* *~ password.pl

distclean: clean
	$(RM) -f *.cgi dbserver dbserver_ini.pl maintenance.html

